#include<bits/stdc++.h>
using namespace std;
const int N=2*1e5+10;
int T,n,a[N],ans;
void dfs(int x,int xm,int ym,int s){
    int i,j;
    if(x>n){
        ans=max(ans,s);
        return;
    }
    if(a[x]==xm){
        dfs(x+1,xm,ym,s+xm);
    }
    else{
        dfs(x+1,a[x],ym,s);
    }
    if(a[x]==ym){
        dfs(x+1,xm,ym,s+ym);
    }
    else{
        dfs(x+1,xm,a[x],s);
    }
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int i,j;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        for(i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        ans=0;
        dfs(1,0,0,0);
        cout<<ans<<endl;
    }
    return 0;
}
